/*
 * @Author: 邹威鹏(944740645@qq.com)
 * @remarks:
 */
/*
 * @Author: 邹威鹏(944740645@qq.com)
 * @remarks:
 */
/*
 * @Author: 邹威鹏(944740645@qq.com)
 * @remarks:
 */
import axios from '../../../../utils/axios'
import { children } from '../../../../utils/utils'

const app = getApp()
Page({
	data: {
		childrenDataList: '',
		curChildrenHealthData: '',
	},

	async onLoad(options) {
		let childrenRes = await children.getMyChildren()
		console.log('查询我的小孩数据', childrenRes)
		if (childrenRes.data.length == 0)
			this.setData({
				childrenDataList: false,
			})
		// 查询我的小孩健康数据测试
		let healthRes = await children.getMyChildrenHealthData(
			childrenRes.data[0].id
		) // 默认第一个小孩的健康数据
		console.log('默认第一个小孩的健康数据',healthRes)
		this.setData({
			curChildrenHealthData: healthRes.data.content,
			childrenDataList: childrenRes.data,
			userInfo: app.globalData.userInfo,
		})
	},
	onReady: function () {},
	onShow: function () {},
	onHide: async function () {},
	onUnload: async function () {},
	onPullDownRefresh: function () {},
	onReachBottom: function () {},
	onShareAppMessage: function () {},
	async changeCurChildren(e) {
		let idx = e.detail.index // 0 || 1
		let id = this.data.childrenDataList[idx].id // 18 || 19
		let res = await children.getMyChildrenHealthData(id)
		console.log('当前小孩', res.data.content[0])
		console.log(res);
		this.setData({
			curChildrenHealthData: res.data.content,
		})
	},
	goToChildrenData() {
		wx.navigateTo({
			url: '/components/page/childrenData/childrenData',
			success: res => {
				res.eventChannel.emit('sendChildrenData', {
					data: this.data.curChildrenHealthData,
				})
			},
		})
	},
})
